package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtDistributorRating;
import com.ruoyi.business.service.IJtDistributorRatingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分销商评分Controller
 * 
 * @author Alan Zhang
 * @date 2025-05-22
 */
@Controller
@RequestMapping("/distributor/rating")
public class JtDistributorRatingController extends BaseController
{
    private String prefix = "distributor/rating";

    @Autowired
    private IJtDistributorRatingService jtDistributorRatingService;

    @RequiresPermissions("distributor:rating:view")
    @GetMapping()
    public String rating()
    {
        return prefix + "/rating";
    }

    /**
     * 查询分销商评分列表
     */
    @RequiresPermissions("distributor:rating:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtDistributorRating jtDistributorRating)
    {
        startPage();
        List<JtDistributorRating> list = jtDistributorRatingService.selectJtDistributorRatingList(jtDistributorRating);
        return getDataTable(list);
    }

    /**
     * 导出分销商评分列表
     */
    @RequiresPermissions("distributor:rating:export")
    @Log(title = "分销商评分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtDistributorRating jtDistributorRating)
    {
        List<JtDistributorRating> list = jtDistributorRatingService.selectJtDistributorRatingList(jtDistributorRating);
        ExcelUtil<JtDistributorRating> util = new ExcelUtil<JtDistributorRating>(JtDistributorRating.class);
        return util.exportExcel(list, "分销商评分数据");
    }

    /**
     * 新增分销商评分
     */
    @RequiresPermissions("distributor:rating:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分销商评分
     */
    @RequiresPermissions("distributor:rating:add")
    @Log(title = "分销商评分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtDistributorRating jtDistributorRating)
    {
        return toAjax(jtDistributorRatingService.insertJtDistributorRating(jtDistributorRating));
    }

    /**
     * 修改分销商评分
     */
    @RequiresPermissions("distributor:rating:edit")
    @GetMapping("/edit/{ratingId}")
    public String edit(@PathVariable("ratingId") Long ratingId, ModelMap mmap)
    {
        JtDistributorRating jtDistributorRating = jtDistributorRatingService.selectJtDistributorRatingByRatingId(ratingId);
        mmap.put("jtDistributorRating", jtDistributorRating);
        return prefix + "/edit";
    }

    /**
     * 修改保存分销商评分
     */
    @RequiresPermissions("distributor:rating:edit")
    @Log(title = "分销商评分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtDistributorRating jtDistributorRating)
    {
        return toAjax(jtDistributorRatingService.updateJtDistributorRating(jtDistributorRating));
    }

    /**
     * 删除分销商评分
     */
    @RequiresPermissions("distributor:rating:remove")
    @Log(title = "分销商评分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtDistributorRatingService.deleteJtDistributorRatingByRatingIds(ids));
    }
}
